<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>$apply和$digest方法</title>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<input type="text" ng-model="name">
</body>
</html>

<script src="../libs/AngularJS.min.js"></script>
<script>
    angular
        .module('myApp', [])
        .controller('myCtrl', ['$scope', function ($scope) {
            /*
             关于$scope.$watch中方法的解释
             参数1：监听改变那个$scope中的变量
             参数2：监听改变的回调函数，函数中的形参分别为
             *    - `newVal` contains the current value of the `watchExpression`
             *    - `oldVal` contains the previous value of the `watchExpression`
             *    - `scope` refers to the current scope
             参数3： boolean类型的值，true表示监听对象中里边属性的变化  false表示只监听对象
             */

            $scope.name = '张三';
            $scope.$watch('name', function (newVal, oldVal, scope) {
                console.log(newVal, oldVal);
                console.log(scope);
            })
        }]);
</script>